package pocker;

import pocker.exceptions.InvalidPlayerCardException;
import pocker.exceptions.InvalidPlayerNameException;

/**
 * Created with IntelliJ IDEA.
 * User: gia
 * Date: 23.08.2012
 * Time: 09:26
 */
public class PlayerTest {

    <T> void assertEquals(T expected, T actual) {

        if (actual != null && !actual.equals(expected))
            throw new RuntimeException("Expected: " + expected + ", actual: " + actual);
        if (expected != null && !expected.equals(actual))
            throw new RuntimeException("Expected: " + expected + ", actual: " + actual);

    }

    void assertTrue(boolean isTrue) {
        if (!isTrue)
            throw new RuntimeException("Value not true: " + isTrue);

    }

    public void testInitialisePlayerCorrectly() throws InvalidPlayerNameException, InvalidPlayerCardException {

        String playerName = "playerName";
        Player player = new Player(3, 2, playerName);

        assertEquals(playerName, player.getName());

    }

    public void testEmptyPlayerNameNotAccepted() throws InvalidPlayerCardException {

        String emptyName = "";
        boolean throwsException = false;

        try {
            new Player(2, 4, emptyName);
        } catch (InvalidPlayerNameException e) {
            throwsException = true;
        }

        assertTrue(throwsException);

    }

    public static void main(String[] args) {
        PlayerTest playerTest = new PlayerTest();

        System.out.print("Test InitialisePlayerCorrectly ................");

        try {
            playerTest.testInitialisePlayerCorrectly();
            System.out.println("Passed");
        } catch (RuntimeException e) {
            System.out.println("Failed.");
        } catch (InvalidPlayerNameException e) {
            System.out.println("Failed.");
        } catch (InvalidPlayerCardException e) {
            System.out.println("Failed.");
        }

        System.out.print("Test EmptyPlayerNameNotAccepted ................");

        try {
            playerTest.testEmptyPlayerNameNotAccepted();
            System.out.println("Passed");
        } catch (RuntimeException e) {
            System.out.println("Failed");

        } catch (InvalidPlayerCardException e) {
            System.out.println("Failed.");
        }

    }

}


